public class Solution605 {
    public boolean canPlaceFlowers(int[] flowerbed, int n) {
        int count=0;
        for (int i=0;i<flowerbed.length;i++){
            if (flowerbed[i]==0){
                if (!(i>0 && flowerbed[i-1]==1 || i<flowerbed.length-1 && flowerbed[i+1]==1)){
                    flowerbed[i]=1;
                    count++;
                }
            }
        }
        return count>=n;
    }

    public static void main(String[] args) {
        System.out.println(new Solution605().canPlaceFlowers(new int[]{1,0,0,0,1},1));
    }
}
